<?php
namespace Home\Controller;
use Home\Model\TroyListModel;
use Think\Controller;
class TrojanIssuedController extends BaseController  {
    public function index(){
        $this->assign('title','取证配置管理');
        $this->assign('currentname','trojanIssued');
        $this->display();
    }

    public function getTroyList(){
        if(IS_POST){
            $model=new TroyListModel();
            $list=$model->getTroyList($_POST);
            $this->ajaxReturn($list);
        }
    }

    public function getTroyByName(){
        if(IS_POST){
            $model=new TroyListModel();
            $list=$model->getTroyByNmae(I('post.troyname'));
            $this->ajaxReturn( array('data'=>$list),'json');
        }
    }


    public function addTroy(){
        if(IS_POST){
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     102400000 ;// 设置附件上传大小
            $upload->exts      =     array('apk','exe');// 设置附件上传类型
            $upload->rootPath  =     './Public/Uploads/Troy/'; // 设置附件上传根目录
            $upload->autoSub = false ; //自动子目录保存文件
            $upload->savePath  =     ''; // 设置附件上传（子）目录
            $info   =   $upload->upload();

            if(!$info)
            {
                $this->ajaxReturn( array('data'=>null,'info'=>'取证文件上传失败（只支持exe、apk文件上传）'),'json');
            }else{
                $data = $_POST;
                $data['opttime']=date('Y-m-d H:i:s',time());
                $data['troyfile']='/Uploads/Troy/'.$info['image']['savename'];
                $model=new TroyListModel();
                $data=$model->AddTroy($data);
                $this->ajaxReturn( array('data'=>$data),'json');
            }
        }
    }

    public function delTroyByNo(){
        if(IS_POST){
            $model=new TroyListModel();
            $data=$model->delTroyByNo(I('post.id'));
            $this->ajaxReturn( array('data'=>$data),'json');
        }
    }
}